<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Waits until the output from a process matches one
  of the patterns, a specified time period has passed, or an EOF is seen</title>
 </head>
 <body class="docs"></div>
<div id="layout">
  <div id="layout-content"><div id="function.expect-expectl" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">expect_expectl</h1>
  <p class="verinfo">(PECL expect &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">expect_expectl</span> &mdash; <span class="dc-title">Waits until the output from a process matches one
  of the patterns, a specified time period has passed, or an <acronym title="End Of File">EOF</acronym> is seen
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.expect-expectl-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>expect_expectl</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$expect</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$cases</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$match</code></span>
  ] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
   Waits until the output from a process matches one of the patterns,
   a specified time period has passed, or an <acronym title="End Of File">EOF</acronym> is seen.
  </p>
  <p class="para">
   If <code class="parameter">match</code> is provided, then it is filled with the result of search.
   The matched string can be found in <code class="parameter">match[0]</code>.
   The match substrings (according to the parentheses) in the original pattern can be found
   in <code class="parameter">match[1]</code>, <code class="parameter">match[2]</code>, and so
   on, up to <code class="parameter">match[9]</code> (the limitation of libexpect).
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.expect-expectl-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">expect</code></dt>

     <dd>

      <p class="para">
       An Expect stream, previously opened with
       <span class="function"><a href="expect_popen.html" class="function">expect_popen()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">cases</code></dt>

     <dd>

      <p class="para">
       An array of expect cases. Each expect case is an indexed array,
       as described in the following table:
       <table class="doctable table">
        <caption><strong>Expect Case Array</strong></caption>
        
         <thead>
          <tr>
           <th>Index Key</th>
           <th>Value Type</th>
           <th>Description</th>
           <th>Is Mandatory</th>
           <th>Default Value</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>0</td>
           <td>string</td>
           <td>pattern, that will be matched against the output from the stream</td>
           <td>yes</td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td>1</td>
           <td>mixed</td>
           <td>value, that will be returned by this function, if the pattern matches</td>
           <td>yes</td>
           <td class="empty">&nbsp;</td>
          </tr>

          <tr>
           <td>2</td>
           <td>integer</td>
           <td>
            pattern type, one of:
            <a href="expect.constants.html#constants.expect.exp-glob" class="link"><strong><code>EXP_GLOB</code></strong></a>,
            <a href="expect.constants.html#constants.expect.exp-exact" class="link"><strong><code>EXP_EXACT</code></strong></a>
            or
            <a href="expect.constants.html#constants.expect.exp-regexp" class="link"><strong><code>EXP_REGEXP</code></strong></a>
           </td>
           <td>no</td>
           <td><a href="expect.constants.html#constants.expect.exp-glob" class="link"><strong><code>EXP_GLOB</code></strong></a></td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.expect-expectl-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns value associated with the pattern that was matched.
  </p>
  <p class="para">
   On failure this function returns:
   <a href="expect.constants.html#constants.expect.exp-eof" class="link"><strong><code>EXP_EOF</code></strong></a>,
   <a href="expect.constants.html#constants.expect.exp-timeout" class="link"><strong><code>EXP_TIMEOUT</code></strong></a>
   or
   <a href="expect.constants.html#constants.expect.exp-fullbuffer" class="link"><strong><code>EXP_FULLBUFFER</code></strong></a>
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.expect-expectl-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>0.2.1</td>
       <td>
       Prior to version 0.2.1, in <code class="parameter">match</code> parameter a match string was returned,
       not an array of match substrings.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.expect-expectl-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4320">
    <p><strong>Example #1 <span class="function"><strong>expect_expectl()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Copies&nbsp;file&nbsp;from&nbsp;remote&nbsp;host:<br /></span><span style="color: #0000BB">ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect.timeout"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stream&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"expect://scp&nbsp;user@remotehost:/var/log/messages&nbsp;/home/user/messages.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"r"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$cases&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;array(pattern,&nbsp;value&nbsp;to&nbsp;return&nbsp;if&nbsp;pattern&nbsp;matched)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">array(</span><span style="color: #DD0000">"password:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;password"</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">"yes/no)?"</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;yes/no"</span><span style="color: #007700">)<br />);<br /><br />while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(</span><span style="color: #0000BB">expect_expectl</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$cases</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;password"</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my&nbsp;password\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">"asked&nbsp;for&nbsp;yes/no"</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"yes\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">EXP_TIMEOUT</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #0000BB">EXP_EOF</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;break&nbsp;both&nbsp;the&nbsp;switch&nbsp;statement&nbsp;and&nbsp;the&nbsp;while&nbsp;loop<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die&nbsp;</span><span style="color: #DD0000">"Error&nbsp;has&nbsp;occurred!"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.expect-expectl-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="expect_popen.html" class="function" rel="rdfs-seeAlso">expect_popen()</a> - Execute command via Bourne shell, and open the PTY stream to
  the process</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>